
<template>
  <app-layout viewName="mail_activityaclistview" viewTitle="活动列表视图" :className="{ 'view-container': true, 'default-mode-view': true, 'dedataview': true, 'mail-activity-ac-list-view': true }" layoutMode="VIEW" :isShowUserInfo="isDefaultView()" :openMode="openMode" @close-view="closeView($event)">
    <template slot="headerLeft">
      <div class="view-header-left">

        <div class="view-caption" v-if="isDefaultView()">{{$t(model.srfCaption)}}</div>
        <modal-breadcrumb v-if="isModalView()"/>
      </div>
    </template>
    <template slot="headerRight">
      <div class="view-header-right">
        <app-header-menus :toolbarModel="toolBarModels" @menu-click="toolbar_click($event)" mode="view" :openMode="openMode" :isEnableQuickSearch="true" searchPlaceholder="请输入显示名称" v-model="query" @search="onSearch($event)"/>
      </div>
    </template>
    <template slot="content">
      <div class="view-content-wrapper">
                    <view_searchform 
                :viewState="viewState"  
                :viewparams="viewparams" 
                :context="context" 
                :showBusyIndicator="true"
                v-show="isExpandSearchForm"
                loaddraftAction="FilterGetDraft"
                loadAction="FilterGet"
            
                name="searchform"  
                ref='searchform' 
                @save="searchform_save($event)"  
                @search="searchform_search($event)"  
                @load="searchform_load($event)"  
                @closeview="closeView($event)">
            </view_searchform>
            <view_dataview 
                :viewState="viewState"  
                :viewparams="viewparams" 
                :context="context" 
                :isSingleSelect="isSingleSelect" 
                createAction="Create"
                removeAction="Remove"
                updateAction="Update"
                fetchAction="FetchDefault"
                :showBusyIndicator="true" 
                name="dataview"  
                ref='dataview' 
                @selectionchange="dataview_selectionchange($event)"  
                @beforeload="dataview_beforeload($event)"  
                @rowdblclick="dataview_rowdblclick($event)"  
                @remove="dataview_remove($event)"  
                @load="dataview_load($event)"  
                @closeview="closeView($event)">
            </view_dataview>


      </div>
    </template>
  </app-layout>
</template>

<script lang='tsx'>
import { Vue, Component, Prop, Provide, Emit, Watch } from 'vue-property-decorator';
import { Subject } from 'rxjs';
import { UIActionTool, Util } from '@/utils';
import { VueLifeCycleProcessing, DataViewBase } from '@/crm-core';
import Mail_activityService from '@/service/mail-activity/mail-activity-service';

import DataViewEngine from '@engine/view/data-view-engine';


/**
 * 活动列表视图基类
 *
 * @export
 * @class Mail_activityAcListViewBase
 * @extends {DataViewBase}
 */
@Component({})
@VueLifeCycleProcessing
export default class Mail_activityAcListViewBase extends DataViewBase {

    /**
     * 实体服务对象
     *
     * @type {Mail_activityService}
     * @memberof Mail_activityAcListViewBase
     */
    public appEntityService: Mail_activityService = new Mail_activityService;

    /**
     * 数据变化
     *
     * @param {*} val
     * @returns {*}
     * @memberof Mail_activityAcListViewBase
     */
    @Emit() 
    public viewDatasChange(val: any):any {
        return val;
    }

	/**
	 * 视图标识
	 *
	 * @type {string}
	 * @memberof Mail_activityAcListViewBase
	 */
	public viewtag: string = 'ba076d124b2976d7f301c963d3b75db4';

    /**
     * 父数据对象
     *
     * @protected
     * @type {*}
     * @memberof Mail_activityAcListViewBase
     */
    protected srfparentdata: any = {};

	/**
	 * 自定义视图导航上下文集合
	 *
	 * @type {*}
	 * @memberof Mail_activityAcListViewBase
	 */
    protected customViewNavContexts:any ={
    };

	/**
	 * 自定义视图导航参数集合
	 *
	 * @type {*}
	 * @memberof Mail_activityAcListViewBase
	 */
    protected customViewParams:any ={
    };

    /**
     * 视图模型数据
     *
     * @type {*}
     * @memberof Mail_activityAcListViewBase
     */
    public model: any = {
        srfCaption: 'entities.mail_activity.views.aclistview.caption',
        srfTitle: 'entities.mail_activity.views.aclistview.title',
        srfSubTitle: 'entities.mail_activity.views.aclistview.subtitle',
        dataInfo: ''
    }

    /**
     * 容器模型
     *
     * @type {*}
     * @memberof Mail_activityAcListViewBase
     */
    public containerModel: any = {
        view_toolbar: { name: 'toolbar', type: 'TOOLBAR' },
        view_searchform: { name: 'searchform', type: 'SEARCHFORM' },
        view_dataview: { name: 'dataview', type: 'DATAVIEW' },
    };

    /**
     * 视图状态订阅对象
     *
     * @private
     * @type {Subject<{action: string, data: any}>}
     * @memberof Mail_activityAcListViewBase
     */
    public viewState: Subject<ViewState> = new Subject();

    /**
     * 工具栏模型
     *
     * @type {*}
     * @memberof Mail_activityAcListView
     */
    public toolBarModels: any = {
    };



    /**
     * 视图引擎
     *
     * @public
     * @type {Engine}
     * @memberof Mail_activityAcListViewBase
     */
    public engine: DataViewEngine = new DataViewEngine();
	

    /**
     * 引擎初始化
     *
     * @public
     * @memberof Mail_activityAcListViewBase
     */
    public engineInit(): void {
        this.engine.init({
            view: this,
            opendata: (args: any[], params?: any, $event?: any, xData?: any) => {
                this.opendata(args, params, $event, xData);
            },
            newdata: (args: any[], params?: any, $event?: any, xData?: any) => {
                this.newdata(args, params, $event, xData);
            },
            searchform: this.$refs.searchform,
            dataview: this.$refs.dataview,
            keyPSDEField: 'mail_activity',
            majorPSDEField: 'display_name',
            isLoadDefault: true,
        });
    }


    /**
     * searchform 部件 save 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Mail_activityAcListViewBase
     */
    public searchform_save($event: any, $event2?: any) {
        this.engine.onCtrlEvent('searchform', 'save', $event);
    }


    /**
     * searchform 部件 search 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Mail_activityAcListViewBase
     */
    public searchform_search($event: any, $event2?: any) {
        this.engine.onCtrlEvent('searchform', 'search', $event);
    }


    /**
     * searchform 部件 load 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Mail_activityAcListViewBase
     */
    public searchform_load($event: any, $event2?: any) {
        this.engine.onCtrlEvent('searchform', 'load', $event);
    }


    /**
     * dataview 部件 selectionchange 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Mail_activityAcListViewBase
     */
    public dataview_selectionchange($event: any, $event2?: any) {
        this.engine.onCtrlEvent('dataview', 'selectionchange', $event);
    }


    /**
     * dataview 部件 beforeload 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Mail_activityAcListViewBase
     */
    public dataview_beforeload($event: any, $event2?: any) {
        this.engine.onCtrlEvent('dataview', 'beforeload', $event);
    }


    /**
     * dataview 部件 rowdblclick 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Mail_activityAcListViewBase
     */
    public dataview_rowdblclick($event: any, $event2?: any) {
        this.engine.onCtrlEvent('dataview', 'rowdblclick', $event);
    }


    /**
     * dataview 部件 remove 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Mail_activityAcListViewBase
     */
    public dataview_remove($event: any, $event2?: any) {
        this.engine.onCtrlEvent('dataview', 'remove', $event);
    }


    /**
     * dataview 部件 load 事件
     *
     * @param {*} [args={}]
     * @param {*} $event
     * @memberof Mail_activityAcListViewBase
     */
    public dataview_load($event: any, $event2?: any) {
        this.engine.onCtrlEvent('dataview', 'load', $event);
    }



    /**
     * 打开新建数据视图
     *
     * @param {any[]} args
     * @param {*} [params]
     * @param {*} [fullargs]
     * @param {*} [$event]
     * @param {*} [xData]
     * @memberof Mail_activityAcListView
     */
    public newdata(args: any[],fullargs?:any[], params?: any, $event?: any, xData?: any) {
        const data: any = {};
        let curViewParam = JSON.parse(JSON.stringify(this.context));
        if(args.length >0){
            Object.assign(curViewParam,args[0]);
        }
        const deResParameters: any[] = [];
        const parameters: any[] = [
            { pathName: 'mail_activities', parameterName: 'mail_activity' },
        ];
        const _this: any = this;
        const openDrawer = (view: any, data: any) => {
            let container: Subject<any> = this.$appdrawer.openDrawer(view, curViewParam, data);
            container.subscribe((result: any) => {
                if (!result || !Object.is(result.ret, 'OK')) {
                    return;
                }
                if (!xData || !(xData.refresh instanceof Function)) {
                    return;
                }
                xData.refresh(result.datas);
            });
        }
        const view: any = {
            viewname: 'mail-activity-main-view9-edit-mode', 
            height: 0, 
            width: 0,  
            title: this.$t('entities.mail_activity.views.mainview9_editmode.title'),
            placement: 'DRAWER_TOP',
        };
        openDrawer(view, data);
    }


    /**
     * 打开编辑数据视图
     *
     * @param {any[]} args
     * @param {*} [params]
     * @param {*} [fullargs]
     * @param {*} [$event]
     * @param {*} [xData]
     * @memberof Mail_activityAcListView
     */
    public opendata(args: any[],fullargs?:any[],params?: any, $event?: any, xData?: any) {
        const data: any = {};
        let curViewParam = JSON.parse(JSON.stringify(this.context));
        if(args.length >0){
            Object.assign(curViewParam,args[0]);
        }
        const deResParameters: any[] = [];
        const parameters: any[] = [
            { pathName: 'mail_activities', parameterName: 'mail_activity' },
        ];
        const _this: any = this;
        const openDrawer = (view: any, data: any) => {
            let container: Subject<any> = this.$appdrawer.openDrawer(view, curViewParam, data);
            container.subscribe((result: any) => {
                if (!result || !Object.is(result.ret, 'OK')) {
                    return;
                }
                if (!xData || !(xData.refresh instanceof Function)) {
                    return;
                }
                xData.refresh(result.datas);
            });
        }
        const view: any = {
            viewname: 'mail-activity-main-view9-edit-mode', 
            height: 0, 
            width: 0,  
            title: this.$t('entities.mail_activity.views.mainview9_editmode.title'),
            placement: 'DRAWER_TOP',
        };
        openDrawer(view, data);
    }




    /**
     * 销毁视图回调
     *
     * @memberof Mail_activityAcListViewBase
     */
    public destroyed(){
        if(this.viewDefaultUsage){
            let localStoreLength = Object.keys(localStorage);
            if(localStoreLength.length > 0){
                localStoreLength.forEach((item:string) =>{
                if(item.startsWith(this.context.srfsessionid)){
                    localStorage.removeItem(item);
                }
                })
            }
        }
    }

    /**
     * 是否单选
     *
     * @type {boolean}
     * @memberof Mail_activityAcListView
     */
    public isSingleSelect: boolean = false;

    /**
     * 视图唯一标识
     *
     * @type {string}
     * @memberof Mail_activityAcListView
     */
    public viewUID: string = 'odoo-mail-mail-activity-ac-list-view';

    /**
     * 搜索值
     *
     * @type {string}
     * @memberof Mail_activityAcListView
     */
    public query: string = '';

    /**
     * 是否展开搜索表单
     *
     * @type {boolean}
     * @memberof Mail_activityAcListView
     */
    public isExpandSearchForm: boolean = false;

    /**
     * 快速搜索
     *
     * @param {*} $event
     * @memberof Mail_activityAcListView
     */
    public onSearch($event: any): void {
        const refs: any = this.$refs;
        if (refs.dataview) {
            refs.dataview.refresh({});
        }
    }

}
</script>

<style lang='less'>
@import './mail-activity-ac-list-view.less';
</style>